package dao.impl;

import dao.DeviceDao;
import domain.Device;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.Map;

/**
 * Created by chen<chen@youjianghr.com> on 2015/7/20.
 *
 * @author chen<chen@youjianghr.com>
 */
@Repository
public class DeviceDaoImpl extends BaseGenericDao<Device, Long> implements DeviceDao {
    @Override
    public void updateLastUse(long id) {

        Map<String, Object> param = newMapBuilder()
                .put("id", id)
                .put("latest_use", new Date())
                .build();
        update("update-last-use", param);
    }

    @Override
    public Device getByUserIdAndIMEI(long userId, String IMEI) {
        Device device = null;
        Map<String, Object> param = newMapBuilder()
                .put("account_id", userId)
                .put("imei", IMEI)
                .build();

        device = queryOne("select-by-userid-imei", param);

        return device;
    }
}
